package com.cnbot.httpsdk.place.m;

import android.content.Context;

import com.cnbot.dchttpsdk.base.BaseModel;
import com.cnbot.dchttpsdk.constant.HttpCode;
import com.cnbot.dchttpsdk.helper.OnSubscriberListener;
import com.cnbot.dchttpsdk.rx.DefaultSubscriber;
import com.cnbot.httpsdk.api.ApiHelper;
import com.cnbot.httpsdk.bean.AirportFlightEntity;
import com.cnbot.httpsdk.bean.AirportFlightEntitys;
import com.cnbot.httpsdk.bean.BasAirportBean;
import com.cnbot.httpsdk.bean.BaseResBean;
import com.google.gson.Gson;

import java.util.List;

import rx.Subscriber;

/**
 * 描述：
 * 作者：dc on 2019/1/18 17:58
 * 邮箱：597210600@qq.com
 */
public class PlaceCondModel extends BaseModel {

    public PlaceCondModel(Context context) {
        super(context);
    }

    public void getByPlaceCond(int pageNo ,int pageSize , String airportCode ,String aord ,String airlineCode ,String airlineName ,String queryDate ) {
        Subscriber subscriber = new DefaultSubscriber(new OnSubscriberListener<Object>() {
            @Override
            public void onNext(Object baseRes) {
                if (baseRes != null) {
                    BaseResBean bean = (BaseResBean) baseRes;
                    int code = bean.getCode();
                    if (code == HttpCode.SUCCESS) {
                        AirportFlightEntitys airportFlightEntitys = new Gson().fromJson(bean.getDataMap().toString(),AirportFlightEntitys.class);
                        int pageNo = airportFlightEntitys.getTotalCount();


                        List<AirportFlightEntity> list = airportFlightEntitys.getPageList();


                        if(list != null && list.size() > 0){
                            for (int i = 0; i < list.size(); i++) {
                                AirportFlightEntity airportFlightEntity = list.get(i);
                                String airName = airportFlightEntity.getAirlineName();
                            }
                        }
                    } else if(code == HttpCode.FAIL){

                    }
                }
            }

            @Override
            public void onError(Throwable e) {

            }
        }, mContext);
        ApiHelper.getByPlaceCond(subscriber, pageNo, pageSize, airportCode, aord, airlineCode, airlineName, queryDate);
        addSubscribe(subscriber);
    }

    public void getBasicsData() {
        Subscriber subscriber = new DefaultSubscriber(new OnSubscriberListener<Object>() {
            @Override
            public void onNext(Object baseRes) {
                if (baseRes != null) {
                    BasAirportBean basAirportBean = (BasAirportBean) baseRes;
                    BasAirportBean.DomesticBean domesticBean = basAirportBean.getDomestic();
                    String abbr = domesticBean.getC().get(0).getAirportNameCnAbbr();
                }
            }

            @Override
            public void onError(Throwable e) {

            }
        }, mContext);
        ApiHelper.getBasicsAir(subscriber);
        addSubscribe(subscriber);
    }
}
